package com.xdqzy.baseline.common.exception;

import com.xdqzy.baseline.common.enums.RespCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author dengmawei
 * @version 1.0.0
 * @ClassName BusinessException.java
 * @Description TODO
 * @createTime 2020年10月24日 22:56:00
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class BusinessException extends RuntimeException {
    /**
     * 数据
     */
    private final Object data;

    /**
     * 返回码
     */
    private final int code;

    /**
     * 错误信息
     */
    private final String errorMsg;

    /**
     * 构造器
     * @param code 错误信息码
     */
    public BusinessException(int code) {
        super(String.valueOf(code));
        this.data = null;
        this.code = code;
        this.errorMsg = null;
    }

    /**
     * 构造器
     * @param code 错误信息码
     * @param errorMessage 错误信息
     */
    public BusinessException(int code, String errorMessage) {
        super(String.valueOf(code) + " " + errorMessage);
        this.data = null;
        this.code = code;
        this.errorMsg = errorMessage;
    }


    public BusinessException(RespCode respCode){
        this(respCode.getCode(),respCode.getMsg());
    }
    /**
     * 构造器
     * @param data 异常数据
     * @param code 错误信息码
     * @param errorMessage 错误信息
     */
    public BusinessException(Object data, int code, String errorMessage) {
        super(String.valueOf(code) + " " + errorMessage);
        this.data = data;
        this.code = code;
        this.errorMsg = errorMessage;
    }

    /**
     * 构造器
     * @param code 错误码
     * @param throwable 异常
     */
    public BusinessException(int code, Throwable throwable) {
        super(throwable);
        this.data = null;
        this.code = code;
        this.errorMsg = null;
    }

    /**
     * 构造器
     * @param data 异常数据
     * @param code 错误码
     */
    public BusinessException(Object data, int code) {
        super(String.valueOf(code));
        this.data = data;
        this.code = code;
        this.errorMsg = null;
    }

    /**
     * 构造器
     * @param data 异常数据
     * @param code 错误码
     * @param throwable 异常
     */
    public BusinessException(Object data, int code, Throwable throwable) {
        super(throwable);
        this.data = data;
        this.code = code;
        this.errorMsg = null;
    }


}
